package lcz;

import java.awt.CardLayout;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * @author lcz
 * @desc 控制台pp
 * @mail lcz_0130@163.com
 * @date 2023/12/19
 */

public class ConsolePP extends JFrame implements ActionListener {
    private static final long serialVersionUID = 8778607205802017522L;
    every[] mj = new every[109];
    int currentmj;
    int currentPlayer;
    int jbDown = -1;
    every nowMj = null;
    JLabel nowMajiang = new JLabel("");
    JLabel nowMajiang1 = new JLabel("");
    JLabel nowMajiang2 = new JLabel("");
    JLabel nowMajiang3 = new JLabel("");
    JLabel no = new JLabel("");
    JLabel winned = new JLabel("");
    boolean op = false;
    boolean op2 = false;
    Player[] competitor = new Player[6];
    JPanel jp = new JPanel();
    JPanel win = new JPanel();
    JButton[] jb = new JButton[14];
    JButton jbTouch = new JButton("碰");
    JButton jbKong = new JButton("杠");
    JButton jbWin = new JButton("胡");
    JButton jbPass = new JButton("过");
    JButton jbWin2 = new JButton("自摸");
    JButton sure = new JButton("确定");
    JLabel[] jl = new JLabel[14];
    ImageIcon img1 = new ImageIcon("picture/diaonao1.jpg");
    ImageIcon img2 = new ImageIcon("picture/diaonao2.jpg");
    ImageIcon img3 = new ImageIcon("picture/diaonao3.jpg");
    JLabel jlCom1;
    JLabel jlCom2;
    JLabel jlCom3;
    CardLayout cl;
    every lit;

    public void initialize() {
        int i;
        for(i = 0; i <= 108; ++i) {
            this.mj[i] = new every();
        }

        for(i = 0; i <= 5; ++i) {
            this.competitor[i] = new Player();
        }

        for(i = 1; i <= 108; ++i) {
            this.mj[i].setNumber(i % 9 + 1);
            if (i <= 36) {
                this.mj[i].setColor(1);
            } else if (i >= 37 && i <= 72) {
                this.mj[i].setColor(2);
            } else {
                this.mj[i].setColor(3);
            }

            this.mj[i].setIf_Konged(false);
            this.mj[i].setIf_Touched(false);
            String a = new String("picture/");
            a = a + (i % 9 + 1);
            if (this.mj[i].getColor() == 1) {
                a = a + "tong.jpg";
            } else if (this.mj[i].getColor() == 2) {
                a = a + "tiao.jpg";
            } else {
                a = a + "wan.jpg";
            }

            this.mj[i].setImage(a);
        }

    }

    public void riffle() {
        for(int i = 1; i < 109; ++i) {
            int j = (int)(Math.random() * 10000.0) % (109 - i) + i;
            every temp = this.mj[i];
            this.mj[i] = this.mj[j];
            this.mj[j] = temp;
        }

    }

    public void deal() {
        int i;
        for(i = 1; i <= 13; ++i) {
            this.competitor[0].hold[i] = this.mj[i];
            this.competitor[1].hold[i] = this.mj[i + 13];
            this.competitor[2].hold[i] = this.mj[i + 26];
            this.competitor[3].hold[i] = this.mj[i + 39];
        }

        for(i = 0; i < 4; ++i) {
            for(int j = 14; j <= 18; ++j) {
                this.competitor[i].hold[j].setColor(1000);
            }
        }

    }

    public every getMj() {
        if (this.currentmj == 109) {
            this.peace();
        }

        int i = this.currentmj++;
        return this.mj[i];
    }

    public void sort_mj(Player[] a, int i) {
        int[] wage = new int[19];

        int j;
        for(j = 1; j <= 18; ++j) {
            if (!a[i].hold[j].getIf_Konged() && !a[i].hold[j].getIf_Touched()) {
                wage[j] = 0;
            } else {
                wage[j] = 1;
            }
        }

        for(j = 18; j >= 2; --j) {
            for(int k = 1; k < j; ++k) {
                every temp = a[i].hold[k];
                int x = wage[k];
                if (a[i].hold[k + 1].getColor() * 10 + wage[k + 1] * 100 + a[i].hold[k + 1].getNumber() < wage[k] * 100 + a[i].hold[k].getColor() * 10 + a[i].hold[k].getNumber()) {
                    a[i].hold[k] = a[i].hold[k + 1];
                    a[i].hold[k + 1] = temp;
                    wage[k] = wage[k + 1];
                    wage[k + 1] = x;
                }
            }
        }

    }

    public boolean If_double7(Player[] a, int c) {
        int i = 1;

        while(i <= 14) {
            if (!a[c].hold[i].getIf_Konged() && !a[c].hold[i].getIf_Touched()) {
                if (a[c].hold[i].getColor() == a[c].hold[i + 1].getColor() && a[c].hold[i].getNumber() == a[c].hold[i + 1].getNumber()) {
                    i += 2;
                    continue;
                }

                return false;
            }

            return false;
        }

        return true;
    }

    public boolean If_Win(Player[] a, int c, int[] b) {
        if (this.If_double7(a, c)) {
            return true;
        } else {
            boolean flag = true;
            this.sort_mj(a, c);
            int i = 1;
            int j = 1;
            int co = a[c].hold[1].getColor();
            int If_jiang = 0;

            for(int j1 = 1; j1 <= 18; ++j1) {
                if (a[c].hold[j1].getIf_Konged() || a[c].hold[j1].getIf_Touched()) {
                    b[j1] = 1;
                }
            }

            while(i < 19 && a[c].hold[i].getColor() < 4 && !a[c].hold[i].getIf_Konged() && !a[c].hold[i].getIf_Touched()) {
                if (a[c].hold[i].getColor() == co) {
                    ++i;
                } else {
                    co = a[c].hold[i].getColor();
                    if (this.ok(j, i - 1, a, c, b) == 0 && this.jiang(j, i - 1, a, c, b) == 0) {
                        flag = false;
                    } else if (this.jiang(j, i - 1, a, c, b) == 1) {
                        if (If_jiang==0) {
                            If_jiang=1;
                        } else {
                            flag = false;
                        }
                    }

                    j = i;
                }
            }

            if (ok(j, i - 1, a, c, b) == 1 && If_jiang==1 && flag) {
                flag = true;
            } else if (If_jiang==0 && this.jiang(j, i - 1, a, c, b) == 1 && flag) {
                flag = true;
            } else {
                flag = false;
            }

            return flag;
        }
    }

    public int ok(int i, int j, Player[] a, int c, int[] b) {
        int x = 1;

        int k;
        for(k = i; k <= j; ++k) {
            b[k] = 0;
        }

        for(k = i; k <= j; ++k) {
            if (a[c].hold[k].getIf_Konged() || a[c].hold[k].getIf_Touched()) {
                b[k] = 1;
            }

            if (b[k] != 1) {
                if (k + 2 <= j && a[c].hold[k + 1].getNumber() == a[c].hold[k].getNumber() && a[c].hold[k + 2].getNumber() == a[c].hold[k].getNumber()) {
                    b[k] = b[k + 1] = b[k + 2] = 1;
                } else {
                    int a1 = -1;

                    for(int p = k + 1; p <= j; ++p) {
                        if (a[c].hold[p].getNumber() == a[c].hold[k].getNumber() + 1 && b[p] == 0) {
                            a1 = p;
                        }

                        if (a[c].hold[p].getNumber() == a[c].hold[k].getNumber() + 2 && b[p] == 0 && a1 != -1) {
                            b[k] = 1;
                            b[a1] = 1;
                            b[p] = 1;
                            a1 = -2;
                            break;
                        }
                    }

                    if (a1 != -2) {
                        x = 0;
                    }
                }
            }

            if (b[k] != 1) {
                x = 0;
            }
        }

        return x;
    }

    public int jiang(int i, int j, Player[] a, int c, int[] b) {
        for(int k = i; k <= j; ++k) {
            if (a[c].hold[k].getNumber() == a[c].hold[k + 1].getNumber() && this.ok(i, k - 1, a, c, b) == 1 && this.ok(k + 2, j, a, c, b) == 1) {
                return 1;
            }
        }

        return 0;
    }

    public boolean If_Touch(every e, Player[] a, int c) {
        for(int i = 1; i <= 17; ++i) {
            if (a[c].hold[i].getColor() == e.getColor() && a[c].hold[i].getNumber() == e.getNumber() && a[c].hold[i + 1].getColor() == e.getColor() && a[c].hold[i + 1].getNumber() == e.getNumber() && !a[c].hold[i].getIf_Touched() && !a[c].hold[i + 1].getIf_Touched()) {
                return true;
            }
        }

        return false;
    }

    public int If_Kong(every e, Player[] a, int c) {
        for(int i = 1; i <= 16; ++i) {
            if (a[c].hold[i].getColor() == e.getColor() && a[c].hold[i].getNumber() == e.getNumber() && a[c].hold[i + 1].getColor() == e.getColor() && a[c].hold[i + 1].getNumber() == e.getNumber() && a[c].hold[i + 2].getColor() == e.getColor() && a[c].hold[i + 2].getNumber() == e.getNumber()) {
                if (a[c].hold[i].getIf_Touched()) {
                    return -1;
                }

                return 1;
            }
        }

        return -1;
    }

    public int If_Kong2(Player c) {
        for(int i = 1; i <= 15; ++i) {
            int sum = 0;
            if (!c.hold[i].getIf_Konged()) {
                for(int j = 1; j < 4; ++j) {
                    if (c.hold[i].getColor() == c.hold[i + j].getColor() && c.hold[i].getNumber() == c.hold[i + j].getNumber() && c.hold[i].getColor() < 4) {
                        ++sum;
                    }
                }

                if (sum == 3) {
                    return i;
                }
            }
        }

        return -1;
    }

    public void piGetWin(int c, int a) {
        if (a == c) {
            this.winned.setText("玩家" + c + "赢了,他自摸");
        } else if (a != 0) {
            this.winned.setText("玩家" + c + "赢了,玩家" + (a + 1) + "放炮");
        } else {
            this.winned.setText("玩家" + c + "赢了,您放炮");
        }

        this.win.add(this.winned);
        this.win.setVisible(true);
        this.add(this.win);
        this.setBounds(300, 300, 300, 300);
        this.jp.setVisible(false);
    }

    public void peace() {
        this.winned.setText("和局");
        this.win.add(this.winned);
        this.win.setVisible(true);
        this.add(this.win);
        this.setBounds(300, 300, 300, 300);
        this.jp.setVisible(false);
    }

    public void playerGetWin(int a) {
        if (a == 0) {
            this.winned.setText("You winned! 您自摸");
        } else {
            this.winned.setText("You winned! 玩家" + (a + 1) + "放炮");
        }

        this.win.add(this.winned);
        this.win.setVisible(true);
        this.add(this.win);
        this.setBounds(300, 300, 300, 300);
        this.jp.setVisible(false);
    }

    public void playerGetPlay(Player[] a, int c, boolean flag) {
        this.op = flag;

        int njb;
        for(njb = 0; njb < 14; ++njb) {
            this.jb[njb].setVisible(false);
            this.jl[njb].setVisible(false);
        }

        njb = 0;
        int njl = 0;

        for(int i = 1; i <= 18; ++i) {
            if ((a[c].hold[i].getIf_Touched() || a[c].hold[i].getIf_Konged()) && a[c].hold[i].getColor() < 4) {
                this.jl[njl].setIcon(this.competitor[0].hold[i].getImg());
                this.jl[njl++].setVisible(true);
                this.show(true);
            } else if (a[c].hold[i].getColor() < 4) {
                this.jb[njb].setIcon(this.competitor[0].hold[i].getImg());
                this.jb[njb++].setVisible(true);
                this.show(true);
            }
        }

        int[] b = new int[19];
        boolean flag1 = this.If_Win(this.competitor, this.currentPlayer, b);
        if (flag1 && !this.op2) {
            this.jbWin2.setVisible(true);
            this.jbPass.setVisible(true);
            this.op2 = true;
            this.show(true);
        } else if (this.If_Kong2(this.competitor[0]) != -1 && !this.op2) {
            this.jbKong.setVisible(true);
            this.jbPass.setVisible(true);
            this.op2 = true;
            this.show(true);
        } else {
            this.op2 = false;
        }
    }

    public void piGetPlay(Player[] a, int c) {
        this.sort_mj(a, c);
        int[] b = new int[19];
        if (this.If_Win(a, c, b)) {
            this.piGetWin(c, c);
        } else {
            int kong;
            for(kong = 1; kong <= 18; ++kong) {
                System.out.print(b[kong] + " ");
            }

            System.out.println();
            kong = this.If_Kong2(a[c]);
            if (kong != -1) {
                for(int i = 0; i <= 3; ++i) {
                    a[c].hold[kong + i].setIf_Konged(true);
                }

                a[c].hold[18] = this.getMj();
                this.piGetPlay(a, c);
                return;
            }

            for(int i = 1; i <= 18; ++i) {
                if (b[i] == 0 && i <= 18 && a[c].hold[i].getColor() <= 3) {
                    int var10002;
                    if (this.If_same(a[c].hold[i], a[c].hold[i + 1])) {
                        var10002 = b[i]--;
                        if (b[i + 1] == 0) {
                            --b[i + 1];
                        }
                    }

                    if (a[c].hold[i].getNumber() + 1 == a[c].hold[i + 1].getNumber() && a[c].hold[i].getColor() == a[c].hold[i + 1].getColor()) {
                        var10002 = b[i]--;
                        if (b[i + 1] == 0) {
                            --b[i + 1];
                        }
                    } else if (a[c].hold[i].getNumber() + 2 == a[c].hold[i + 1].getNumber() && a[c].hold[i].getColor() == a[c].hold[i + 1].getColor()) {
                        var10002 = b[i]--;
                        if (b[i + 1] == 0) {
                            --b[i + 1];
                        }
                    }
                }
            }

            int temp=0;
            int sum = -55;

            for(int i = 1; i <= 18; ++i) {
                if (b[i] == 0 && a[c].hold[i].getColor() <= 3) {
                    temp = i;
                    break;
                }

                if (b[i] != 1 && b[i] > sum && a[c].hold[i].getColor() <= 3) {
                    sum = b[i];
                    temp = i;
                }
            }

            this.nowMj = a[c].hold[temp];
            a[c].hold[temp] = this.lit;
            this.sort_mj(a, c);
            this.no.setIcon(this.nowMj.getImg());
            this.no.setVisible(true);
            if (c == 1) {
                this.nowMajiang1.setIcon(this.nowMj.getImg());
                this.nowMajiang1.setVisible(true);
            } else if (c == 2) {
                this.nowMajiang2.setIcon(this.nowMj.getImg());
                this.nowMajiang2.setVisible(true);
            } else if (c == 3) {
                this.nowMajiang3.setIcon(this.nowMj.getImg());
                this.nowMajiang3.setVisible(true);
            }
        }

    }

    public boolean If_same(every e1, every e2) {
        return e1.getNumber() == e2.getNumber() && e1.getColor() == e2.getColor();
    }

    public void game() {
        this.initialize();
        this.riffle();
        this.deal();
        this.playerGetPlay(this.competitor, 0, false);
        this.currentmj = 53;
        this.currentPlayer = (int)(Math.random() * 100.0) % 4;

        for(int i = 0; i < 4; ++i) {
            this.sort_mj(this.competitor, i);
        }

        this.gaming();
    }

    public void gaming() {
        if (this.nowMj == null) {
            this.competitor[this.currentPlayer].hold[18] = this.getMj();
            this.sort_mj(this.competitor, this.currentPlayer);
            this.show1();
            System.out.println();
            if (this.currentPlayer == 0) {
                this.playerGetPlay(this.competitor, 0, true);
                return;
            }

            this.piGetPlay(this.competitor, this.currentPlayer);
        }

        if (this.nowMj != null && this.nowMj.getColor() < 4) {
            int addr;
            int sum1;
            if ((addr = this.If_GetWin(this.competitor, (this.currentPlayer + 1) % 4, this.nowMj)) != -1) {
                if (addr == 0) {
                    this.jbWin.setVisible(true);
                    this.jbPass.setVisible(true);
                    this.show(true);
                    return;
                }

                for(sum1 = 1; sum1 <= 18; ++sum1) {
                    this.competitor[addr].hold[sum1] = this.competitor[5].hold[sum1];
                }

                this.piGetWin(addr, this.currentPlayer);
                return;
            }

            int sum2;
            if ((addr = this.If_GetKong(this.competitor, (this.currentPlayer + 1) % 4, this.nowMj)) != -1) {
                if (addr == 0) {
                    this.jbKong.setVisible(true);
                    this.jbTouch.setVisible(true);
                    this.jbPass.setVisible(true);
                    this.show(true);
                    return;
                }

                this.competitor[addr].hold[18] = this.nowMj;
                this.sort_mj(this.competitor, addr);
                sum1 = this.If_Kong2(this.competitor[addr]);

                for(sum2 = 0; sum2 <= 3; ++sum2) {
                    this.competitor[addr].hold[sum1 + sum2].setIf_Konged(true);
                }

                this.currentPlayer = addr;
                this.nowMj = null;
                this.gaming();
                return;
            }

            if ((addr = this.If_GetTouched(this.competitor, (this.currentPlayer + 1) % 4, this.nowMj)) != -1) {
                if (addr == 0) {
                    this.jbTouch.setVisible(true);
                    this.jbPass.setVisible(true);
                    this.show(true);
                    return;
                }

                sum1 = 0;
                sum2 = 0;
                int[] b = new int[19];
                this.sort_mj(this.competitor, addr);
                this.If_Win(this.competitor, addr, b);

                int i;
                for(i = 1; i <= 18; ++i) {
                    if (b[i] == 1) {
                        ++sum1;
                    }
                }

                for(i = 1; i <= 18; ++i) {
                    this.competitor[5].hold[i] = this.competitor[addr].hold[i];
                }

                this.competitor[5].hold[17] = this.nowMj;
                this.competitor[5].hold[18] = this.nowMj;
                this.sort_mj(this.competitor, 5);
                i = this.If_Kong2(this.competitor[5]);
                this.If_Win(this.competitor, 5, b);

                int j;
                for(j = 1; j <= 18; ++j) {
                    if (b[j] == 1) {
                        ++sum2;
                    }
                }

                if (sum1 < sum2) {
                    this.competitor[addr].hold[18] = this.nowMj;
                    this.sort_mj(this.competitor, addr);

                    for(j = 0; j <= 2; ++j) {
                        this.competitor[addr].hold[i + j].setIf_Touched(true);
                    }

                    this.currentPlayer = addr;
                    this.piGetPlay(this.competitor, addr);
                    this.gaming();
                    return;
                }
            }

            this.nowMj = null;
            this.currentPlayer = (this.currentPlayer + 1) % 4;
            this.gaming();
        }

    }

    public int If_GetWin(Player[] a, int c, every nowMj) {
        for(int j = 0; j <= 2; ++j) {
            for(int i = 1; i <= 18; ++i) {
                a[5].hold[i] = a[c].hold[i];
            }

            a[5].hold[18] = nowMj;
            int[] b = new int[19];
            if (this.If_Win(a, 5, b)) {
                return c;
            }

            c = (c + 1) % 4;
        }

        return -1;
    }

    public int If_GetKong(Player[] a, int c, every nowMj) {
        for(int j = 0; j <= 2; ++j) {
            for(int i = 1; i <= 18; ++i) {
                a[5].hold[i] = a[c].hold[i];
            }

            int x;
            if ((x = this.If_Kong(nowMj, a, 5)) != -1) {
                if (x == 2) {
                    nowMj.setIf_Touched(true);
                }

                return c;
            }

            c = (c + 1) % 4;
        }

        return -1;
    }

    int If_GetTouched(Player[] a, int c, every nowMj) {
        for(int j = 0; j <= 2; ++j) {
            for(int i = 1; i <= 18; ++i) {
                a[5].hold[i] = a[c].hold[i];
            }

            if (this.If_Touch(nowMj, a, 5)) {
                return c;
            }

            c = (c + 1) % 4;
        }

        return -1;
    }

    public ConsolePP() {
        this.jlCom1 = new JLabel(this.img1);
        this.jlCom2 = new JLabel(this.img2);
        this.jlCom3 = new JLabel(this.img3);
        this.cl = new CardLayout();
        this.lit = new every();
        this.setTitle("麻将");
        this.jp.setLayout((LayoutManager)null);
        this.win.setLayout((LayoutManager)null);
        this.win.setVisible(false);
        this.win.add(this.winned);
        this.winned.setBounds(20, 20, 200, 200);

        for(int i = 1; i <= 14; ++i) {
            this.jb[i - 1] = new JButton("");
            this.jl[i - 1] = new JLabel("");
            this.jl[i - 1].setBounds(32 + 60 * i, 400, 60, 70);
            this.jb[i - 1].setBounds(32 + 60 * i, 500, 60, 70);
            this.jb[i - 1].addActionListener(this);
            this.jb[i - 1].setVisible(true);
            this.jl[i - 1].setVisible(true);
            this.jp.add(this.jb[i - 1]);
            this.jp.add(this.jl[i - 1]);
        }

        this.sure.setBounds(900, 420, 70, 40);
        this.sure.addActionListener(this);
        this.jp.add(this.sure);
        this.add(this.jp);
        this.setBounds(40, 40, 1000, 650);
        this.jbTouch.setBounds(300, 300, 50, 40);
        this.jbKong.setBounds(350, 300, 50, 40);
        this.jbWin.setBounds(400, 300, 50, 40);
        this.jbWin2.setBounds(400, 300, 80, 40);
        this.jbPass.setBounds(550, 300, 50, 40);
        this.nowMajiang.setBounds(800, 420, 60, 70);
        this.nowMajiang1.setBounds(800, 50, 60, 70);
        this.nowMajiang2.setBounds(550, 70, 60, 70);
        this.nowMajiang3.setBounds(100, 50, 60, 70);
        this.no.setBounds(500, 200, 60, 70);
        this.jp.add(this.nowMajiang);
        this.jp.add(this.nowMajiang1);
        this.jp.add(this.nowMajiang2);
        this.jp.add(this.nowMajiang3);
        this.jp.add(this.no);
        this.nowMajiang.setVisible(false);
        this.nowMajiang1.setVisible(false);
        this.nowMajiang2.setVisible(false);
        this.nowMajiang3.setVisible(false);
        this.no.setVisible(false);
        this.jlCom1.setBounds(890, 100, 20, 200);
        this.jlCom2.setBounds(360, 20, 200, 20);
        this.jlCom3.setBounds(40, 100, 20, 200);
        this.jp.add(this.jlCom3);
        this.jbTouch.setVisible(false);
        this.jbKong.setVisible(false);
        this.jbWin.setVisible(false);
        this.jbWin2.setVisible(false);
        this.jbPass.setVisible(false);
        this.jbTouch.addActionListener(this);
        this.jbKong.addActionListener(this);
        this.jbPass.addActionListener(this);
        this.jbWin.addActionListener(this);
        this.jbWin2.addActionListener(this);
        this.jp.add(this.jbTouch);
        this.jp.add(this.jbKong);
        this.jp.add(this.jbWin);
        this.jp.add(this.jbWin2);
        this.jp.add(this.jbPass);
        this.jp.add(this.jlCom1);
        this.jp.add(this.jlCom2);
        this.game();
        this.setVisible(true);
    }

    public void show1() {
        for(int i = 1; i <= 3; ++i) {
            for(int j = 1; j <= 18; ++j) {
                if (this.competitor[i].hold[j].getColor() == 1) {
                    System.err.print(this.competitor[i].hold[j].getNumber() + "筒  ");
                } else if (this.competitor[i].hold[j].getColor() == 2) {
                    System.err.print(this.competitor[i].hold[j].getNumber() + "条  ");
                } else if (this.competitor[i].hold[j].getColor() == 3) {
                    System.err.print(this.competitor[i].hold[j].getNumber() + "万 ");
                }
            }

            System.out.println();
        }

    }

    public void actionPerformed(ActionEvent e) {
        int i;
        int j;
        if (e.getSource() == this.jbTouch) {
            this.jbTouch.setVisible(false);
            this.jbPass.setVisible(false);
            this.show(true);

            for(i = 1; i <= 18; ++i) {
                this.competitor[5].hold[i] = this.competitor[0].hold[i];
            }

            this.competitor[5].hold[17] = this.nowMj;
            this.competitor[5].hold[18] = this.nowMj;
            this.sort_mj(this.competitor, 5);
            i = this.If_Kong2(this.competitor[5]);
            this.competitor[0].hold[18] = this.nowMj;
            this.sort_mj(this.competitor, 0);

            for(j = 0; j <= 2; ++j) {
                this.competitor[0].hold[i + j].setIf_Touched(true);
            }

            this.currentPlayer = 0;
            this.sort_mj(this.competitor, 0);
            this.playerGetPlay(this.competitor, 0, true);
        }

        if (e.getSource() == this.jbPass) {
            this.jbPass.setVisible(false);
            this.jbTouch.setVisible(false);
            this.jbKong.setVisible(false);
            this.jbWin.setVisible(false);
            this.jbWin2.setVisible(false);
            this.show(true);
            if (this.op2) {
                this.playerGetPlay(this.competitor, 0, true);
            } else {
                this.nowMj = null;
                this.gaming();
            }
        }

        if (e.getSource() == this.jbKong) {
            this.jbKong.setVisible(false);
            this.jbTouch.setVisible(false);
            this.jbPass.setVisible(false);
            this.show(true);

            for(i = 1; i <= 18; ++i) {
                this.competitor[5].hold[i] = this.competitor[0].hold[i];
            }

            if (this.nowMj != null) {
                this.competitor[5].hold[18] = this.nowMj;
            }

            this.sort_mj(this.competitor, 5);
            i = this.If_Kong2(this.competitor[5]);
            this.competitor[0].hold[18] = this.nowMj;
            this.sort_mj(this.competitor, 0);

            for(j = 0; j <= 3; ++j) {
                this.competitor[0].hold[i + j].setIf_Konged(true);
            }

            this.currentPlayer = 0;
            this.nowMj = null;
            this.sort_mj(this.competitor, 0);
            this.gaming();
        }

        if (e.getSource() == this.jbWin) {
            this.jbPass.setVisible(false);
            this.jbTouch.setVisible(false);
            this.jbKong.setVisible(false);
            this.jbWin.setVisible(false);
            this.jbWin2.setVisible(false);
            this.playerGetWin(this.currentPlayer);
        }

        if (e.getSource() == this.jbWin2) {
            this.jbPass.setVisible(false);
            this.jbTouch.setVisible(false);
            this.jbKong.setVisible(false);
            this.jbWin.setVisible(false);
            this.jbWin2.setVisible(false);
            this.playerGetWin(0);
        }

        if (this.op && e.getSource() == this.sure && this.jbDown != -1) {
            this.nowMj = this.competitor[0].hold[this.jbDown + 1];
            this.competitor[0].hold[this.jbDown + 1] = this.lit;
            this.jb[this.jbDown].setBounds(32 + 60 * (this.jbDown + 1), 500, 60, 70);
            this.nowMajiang.setIcon(this.nowMj.getImg());
            this.nowMajiang.setVisible(true);
            this.no.setIcon(this.nowMj.getImg());
            this.no.setVisible(true);
            this.sort_mj(this.competitor, 0);
            this.playerGetPlay(this.competitor, 0, false);
            this.op = false;
            this.gaming();
        }

        for(i = 0; i < 14; ++i) {
            if (this.jb[i] != null && e.getSource() == this.jb[i]) {
                if (this.jbDown != -1) {
                    this.jb[this.jbDown].setBounds(32 + 60 * (this.jbDown + 1), 500, 60, 70);
                }

                this.jb[i].setBounds(32 + 60 * (i + 1), 490, 60, 70);
                this.jbDown = i;
            }
        }

        this.show(true);
    }

    public static void main(String[] args) {
        new ConsolePP();
    }
}
